package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.Filter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * <p>
 *
 * </P>
 *
 * @author mx
 * @date 2021-08-12 18:38
 */
@RestController
@RequestMapping("error")
public class ErrorController {


    @GetMapping
    public String hello(HttpServletResponse httpServletResponse) {
        httpServletResponse.addCookie(new Cookie("fda", "daf"));
        return "hello world";
    }

    @GetMapping("/1")
    public String aa() {

        String password = "123456";
        System.out.println(password);
        return password;
    }

    @GetMapping("/2")
    public String aa2() {

       try {
           Integer.valueOf("adsfasdf");
       }catch (Exception e) {
           throw e;
       }
        return "password";
    }


    @GetMapping("/3")
    public String aa3(String name, HttpServletResponse httpServletResponse) throws Exception {
        File file = new File(name);
        InputStream inputStream = new FileInputStream(file);
        byte[] bf = new byte[10];
        int read = inputStream.read(bf);
        httpServletResponse.getOutputStream().write(bf);
        return "password";
    }



}